#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include<queue>
using namespace std;
#define MAXL 10005
#define MAXLL 0x3f3f3f
void chushidsu(int dsu[],int n)
{
	for (int i = 1; i <= n; i++)
	{
		dsu[i] = i;
	}
}
int find(int x,int dsu[])
{
	if (x == dsu[x])
		return x;
	else
		return dsu[x] = find(dsu[x], dsu);
}
void join(int x,int y,int dsu[])
{
	dsu[find(x, dsu)] = find(y, dsu);
}
int main()
{
	int n, m;
	int dsu[MAXL];
	cin >> n >> m;
	chushidsu(dsu, n);
	while (m--)
	{
		int s,x,y;
		cin >> s;
		if (s == 1)
		{
			cin >> x >> y;
			join(x, y,dsu);
		}
		else
		{
			cin >> x >> y;
			if (find(x, dsu) == find(y, dsu))
			{
				cout << "Y" << endl;
			}
			else
				cout << "N" << endl;
		}
	}
}